Imports System.Xml.Serialization
Imports ToDoList.Model.TaskQuery

Namespace Model
  Public MustInherit Class TaskContainer

    ''' <summary>
    ''' The child tasks of this container. 
    ''' It is in fact the Tasks() array, but this 
    ''' must be hidden in this way because otherwise the
    ''' xml serializer complains
    ''' </summary>
    MustOverride Property ChildTasks() As Task()

    ''' <summary>
    ''' add this child to children of this task
    ''' </summary>
    Public Sub Add(ByVal childTask As Task)
      ReDim Preserve ChildTasks(0 To ChildTasks.Length)
      ChildTasks(ChildTasks.Length - 1) = childTask
    End Sub

    ''' <summary>
    ''' remove child from tasklist
    ''' </summary>
    Public Sub Remove(ByVal childTask As Task)
      Dim lPos As Integer = Array.IndexOf(ChildTasks, childTask)
      If lPos <> ChildTasks.Length - 1 Then
        'no need for this functionality (yet) so why bother
        Throw New ArgumentException("Not supported")
      End If
      'remove last element
      ReDim Preserve ChildTasks(0 To ChildTasks.Length - 2)
    End Sub

  End Class
End Namespace

